package com.liuzhongni.wahahanews.cachetest;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by dllo on 16/1/18.
 */
public class MyDiskCache implements ImageLoader.ImageCache {
    @Override
    public Bitmap getBitmap(String url) {
        String path = Environment.getExternalStorageDirectory().getPath() +url;
        File root = Environment.getExternalStorageDirectory();
        File file = new File(path);
        if(file.exists()){
            Bitmap bm= BitmapFactory.decodeFile(path);
            return bm;
        }else {
            return null;
        }
    }

    public void DiskCache(){
        String url = "";

    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        String path = Environment.getExternalStorageDirectory().getPath()+url;
        if(Environment.getExternalStorageDirectory().getPath().equals(Environment.MEDIA_MOUNTED)){

        }
        File file = new File(path);
        try {
            FileOutputStream outputStream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream);
            outputStream.flush();//
            outputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
